﻿@using PlatformNetCore.Entity
@{
    ViewBag.Title = "编辑分类";
}
@model Category
<style>
    html {
        background-color: #fff;
    }

    .layui-card {
        box-shadow: none;
    }
</style>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="@Url.Action("CategoryEdit","Basis",new { area = "Admin"})" lay-filter="useredit-form">
            <div class="layui-form-item">
                <label class="layui-form-label">分类编号</label>
                <div class="layui-input-block">
                    <input type="text" name="ID" lay-verify="required" readonly="readonly" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分类名称</label>
                <div class="layui-input-block">
                    <input type="text" name="CategoryName" lay-verify="required" placeholder="分类名称" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属类型</label>
                <div class="layui-input-block">
                    <select name="CategoryType" lay-filter="CategoryType">
                        @foreach (var item in (IEnumerable<SelectListItem>)ViewBag.CategoryTypeDLL)
                        {
                            <option value="@item.Value">@item.Text</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="IsAvailable" lay-skin="switch" lay-filter="component-form-switchTest" lay-text="启用|禁用">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序号</label>
                <div class="layui-input-block">
                    <input type="text" name="SortNo" lay-verify="required" placeholder="排序号" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div id="useredit-submit" lay-submit lay-filter="useredit-submit"></div>
        </form>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var $ = layui.$, form = layui.form;

        form.render(null, 'useredit-form');

        /* 监听指定开关 */
        form.on('switch(component-form-switchTest)', function (data) {
            $(this).val(this.checked ? '1' : '0')
        });

        //从父层获取值，json是父层的全局js变量。eval是将该string类型的json串变为标准的json串
        var editObj = parent.editData;
        //表单初始赋值
        form.val('useredit-form', {
            "ID": editObj.ID
            , "CategoryName": editObj.CategoryName
            , "CategoryType": editObj.CategoryType
            , "SortNo": editObj.SortNo
            , "IsAvailable": (editObj.IsAvailable == 1 ? true : false) //开关状态
        });
    });
</script>
